package cn.chencaiju.day09;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

import javafx.util.Pair;

public class GenericTest {
	@Test public void test() {
		List list=new ArrayList<>();
		
		
		list.add(1L);
		list.add("Object");
		list.add(3.1415f);
		Object object = list.get(0);
		Long e=(Long) object;
		String s=(String) list.get(1);
		System.out.println(e+" "+s);
		System.out.println((Float)list.get(2));
	}
	
	/**
	 * 泛型化参数求多个数字的的最大值
	 * @param nums
	 * @return
	 */
	public static  <T extends Number>T max(T...nums){
		if(nums==null||nums.length==0) {
			throw new RuntimeException("参数不能为空！");
		}
		T max=nums[0];
		for(T temp:nums) {
			if(max.doubleValue()<temp.doubleValue()) {
				max=temp;
			}
		}
		return max;
		
	}
	@Test public void testMax() {
		System.out.println(max());
		System.out.println(max(1,2,3,4,2,34,9,-1));
	}
	
}
